package com.mdx.core.impl;

import com.mdx.api.entity.CommunityUserLike;
import com.mdx.api.enums.LikedStatusEnum;
import com.mdx.api.service.CommunityUserLikeService;
import com.mdx.core.repository.CommunityUserLikeRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author : jiagang
 * @date : Created in 2022/4/28 16:31
 */
@Service
@Slf4j
public class CommunityUserLikeServiceImpl implements CommunityUserLikeService {

    @Autowired
    private CommunityUserLikeRepository userLikeRepository;

    /**
     * 点赞
     * @param userLike
     * @return
     */
    @Override
    @Transactional
    public CommunityUserLike insertLikes(CommunityUserLike userLike) {
        // 将点赞人和点赞数存入redis

        userLike.setStatus(LikedStatusEnum.LIKE);
        userLike.setCreateTime(new Date());
        userLike.setUpdateTime(new Date());
        return userLikeRepository.save(userLike);
    }
}
